﻿using System.Collections.Generic;
using MRGSP.SurveyMaster.Core;
using MRGSP.SurveyMaster.Core.Model;
using MRGSP.SurveyMaster.Core.Service.Utils;

namespace MRGSP.SurveyMaster.Service.Utils
{
    public static class QuestionBuilder
    {
        private static readonly IDictionary<ControlType, IQuestionBuilder> Implementations
            = new Dictionary<ControlType, IQuestionBuilder>
                  {
                      { ControlType.Checkbox, new ListBuilder() },
                      { ControlType.Textbox, new ListBuilder() },
                      { ControlType.Radio, new ListBuilder() },
                      { ControlType.Header, new ListHeaderBuilder() },
                      { ControlType.Grid, new GridBuilder()},
                      { ControlType.GridRow, new GridRowBuilder()},
                      { ControlType.GridCell, new GridCellBuilder()},
                      { ControlType.GridCellList, new GridCellListBuilder()},
                      { ControlType.TextArea, new ListBuilder()},
                  };

        public static IQuestionBuilder Get(ControlType type)
        {
            if (Implementations.ContainsKey(type))
                return Implementations[type];
            return Implementations[ControlType.Checkbox];
        }

        public static string Build(Question question)
        {
            return Get(question.Type).Build(question);
        }
    }
}